﻿@model IList<UserAddress>
<div class="container-12  clearfix">
    <div class="grid-2">
        @MyHelper.GetSideNavHtml()
    </div>
    <div class="grid-10">
    <div class="sk-ui-box">
        <div class="header">
            <div class="title">
                收货 & 帐单地址
            </div>
            <div class="extra">
                <ul class="clearfix">
                    <li></li>
                   </ul>
            </div>
        </div>
        <div class="container">
            <div>
                <table class="sk-ui-table-default">
                    <thead>
                        <tr>
                            <th class="addr-consignee">
                                收货人
                            </th>
                            <th class="addr-detail">
                                详细地址
                            </th>
                            <th class="addr-phone">
                                联系电话
                            </th>
                            <th class="addr-operate">
                                操作
                            </th>
                        </tr>
                    </thead>
                    @if (Model.Count > 0)
                    {
                        <tbody>
                            @Model.Each(@<tr class="@item.Css">
                                <td>@item.Item.Receiver
                                </td>
                                <td>@item.Item.Address
                                </td>
                                <td>@(item.Item.Mobile)
                                    @(item.Item.Phone)
                                </td>
                                <td><a class="fancybox fancybox.ajax"  href="/address/address/@item.Item.Id@@" title="编辑地址">
                                        编 辑</a><span class="ml-20"><a href="delete/@item.Item.Id" data-ajax-success="alert(0);" data-ajax="true" data-ajax-method="post">删
                                            除</a></span>
                                </td>
                            </tr>
                        )
                        </tbody>}
                    else
                    {
                        <tbody>
                            <tr>
                                <td colspan="4" class="empty">
                                    <span class="field-validation-error">您还未保存收货地址</span> @*<a href="/address@2/450/500/0" class="thickbox" title="添加地址">添加</a>*@
                                    <a href="/address@@450/500/0" class="dialog-ajax" title="添加地址" data-callback="ajaxFormCallbacks">
                                        添加</a>
                                </td>
                            </tr>
                        </tbody>}
                </table>
            </div>
        </div>
    </div>
</div>
</div>
@section css
{
    <style>
        
    </style>
}
@section js{
    @Url.Sk().StaticJs("jquery.unobtrusive-ajax.min")
    @Url.Sk().StaticJs("jquery.validate.min")
    @Url.Sk().StaticJs("jquery.validate.unobtrusive.min")
    <script type="text/javascript">
        function ajaxFormCallback(result, obj) {
            obj.remove();
        } function ajaxFormCallbacks(result, obj) {
            alert(result.Data);
            obj.remove();
        }
        $(function () {
            $('a.dialog-ajax').click(function () {
                var title = this.title;
                var callback = eval($(this).attr("data-callback"));
                var params = { width: 630, height: 440, modal: 0 };
                var array = this.href.split('@@');
                params.url = array[0];
                params.width = array[1].split('/')[0];
                params.height = array[1].split('/')[1];
                params.modal = array[1].split('/')[2];

                // show a spinner or something via css
                var dialog = $('<div style="display:none" class="loading"></div>').appendTo('body');
                // open the dialog
                dialog.dialog({
                    // add a close listener to prevent adding multiple divs to the document
                    close: function (event, ui) {
                        // remove div with all data and events
                        dialog.remove();
                    },
                    modal: params.modal,
                    width: params.width,
                    height: params.height,
                    title: title,
                    buttons: { '提交': function () {
                        var form = $("form", dialog);

                        var isValid = form.valid();
                        if (isValid) {
                            $.postJSON(params.url, form.serialize(), function (result) {
                                if ($.isFunction(callback)) {
                                    callback(result, dialog);
                                }
                                else {
                                    ajaxFormCallback(result, dialog);
                                }
                            });
                        }

                    }, '取消': function () {
                        dialog.remove();
                    }
                    }
                });
                // load remote content
                dialog.load(
                params.url,
                function (responseText, textStatus, xmlHttpRequest) {
                    // remove the loading class
                    dialog.removeClass('loading');

                    $.validator.unobtrusive.parse(dialog);
                }
            );
                //prevent the browser to follow the link
                return false;
            });
        });
    </script>
}
